package com.example.pojo;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 封装handler方法相关的信息
 * 新增参数：
 * typeSecurity：保存类上的权限信息
 * methodSecurity：保存方法上的权限信息
 *
 * @author kangshuai
 */
public class Handler {

    /**
     * 类
     */
    private Object controller;

    /**
     * 方法
     */
    private Method method;

    /**
     * 路由
     */
    private Pattern pattern;

    /**
     * 参数
     */
    private Map<String, Integer> paramIndexMapping;

    /**
     * 类上的权限
     */
    private String[] typeSecurity;

    /**
     * 方法上的权限
     */
    private String[] methodSecurity;

    public Handler(Object controller, Method method, Pattern pattern) {
        this.controller = controller;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>();
    }

    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Map<String, Integer> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Integer> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }

    public String[] getTypeSecurity() {
        return typeSecurity;
    }

    public void setTypeSecurity(String[] typeSecurity) {
        this.typeSecurity = typeSecurity;
    }

    public String[] getMethodSecurity() {
        return methodSecurity;
    }

    public void setMethodSecurity(String[] methodSecurity) {
        this.methodSecurity = methodSecurity;
    }

    @Override
    public String toString() {
        return "Handler{" +
                "controller=" + controller +
                ", method=" + method +
                ", pattern=" + pattern +
                ", paramIndexMapping=" + paramIndexMapping +
                ", typeSecurity=" + Arrays.toString(typeSecurity) +
                ", methodSecurity=" + Arrays.toString(methodSecurity) +
                '}';
    }
}
